<?php
/* @var $this ProductController */

$this->breadcrumbs=array(
	'Products'=>array('index'), 
    
);
//行业
$category = Category::model()->findByPk($model->catgory_id);
//父级行业，用于导航栏
$category_parent = Category::model()->findByPk($category->zca_parentid);
//顶级行业,用于导航
$category_top = Category::model()->findByPk($category->zca_topid);

//行业顶级ID
$topid = ($category->zca_parentid>0)?(($category->zca_topid>0)?$category->zca_topid:$category->zca_parentid):$category->zca_id;
//分类二级ID
$parentid = ($category->zca_parentid>0)?(($category->zca_topid>0)?$category->zca_parentid:$category->zca_id):0;
//行业属性
$att = AttSelect::model()->getAttMark($model->catgory_id);

if(!empty($att)&&!empty($model->att)){
	
	$attmarkval = AttSelect::model()->getMarkVal($model->att);
	foreach ($att as &$val1) {
		foreach ( (array)$attmarkval as $val2 ) {
			foreach($val1['mark'] as $val3){
				if($val2['za_title']==$val3['za_title']){
					$select = $val2['ztc_id'];
					$param = array_diff($model->att,(array)$val2['ztc_id']);
				}
			}
		}
		$val1['select'] = isset($select)?$select:"";
		if(!isset($param))
			$param = $model->att;
		$val1['param'] = join('-',$param);
		unset($select);
		unset($param);
	}
}
//print_r($att);exit;
/*
if(!empty($att)){
 	foreach ( (array)$att as $key =>  $value) {
		foreach ( (array)$model->att as $k => $v ) {
			if($k == $value['za_id']){
				$att[$key]['select'] = $v;
			}else{
				if(isset($att[$key]['param'])){
					$att[$key]['param'] .= $k.':'.$v.';';
				}else{
					$att[$key]['param'] = $k.':'.$v.';';
				}
			}
		}
	}
}
*/
//分类缓存
$categoryCache = Category::model()->GetCatCache();
$catids = empty($category->zca_arrchildid)?$category->zca_id:$category->zca_arrchildid.",".$category->zca_id;
?>
<!--正文start-->
<div class="w_960 o_a">
    <div class="col_sub w_190 f_l">
        <!--宝贝分类start-->
        <div class="pro_classify">
            <div class="hd bg"><h2 class="fs_14"><a class="c_white" href="javascript:">所有宝贝分类</a></h2></div>
            <div class="bd">
                <ul id="proSort">
                    <?php foreach($categoryCache as $key=>$val){?>    
                        <?php if($val['zca_visible']==1){?>                
                        <li class="item <?php if($topid == $val['zca_id']){?> open<?php }?>">
                            <h3 class="c_green3 bg_x click"><?php echo $val['zca_title'] ?></h3>
                            <div class="list">
                                <ul class="li">
                                <?php if(isset($val['subcat'])){ foreach( $val['subcat'] as $key2=>$val2 ){?>
                                    <?php if($val2['zca_visible']==1){?>  
                                        <li class="<?php if($parentid == $val2['zca_id']){?> open<?php }?>">
                                            <p class="h"><span class="ico ico_fold click2"></span>
                                            <?php if(isset($val2['subcat'])) echo CHtml::link($val2['zca_title'],"javascript:", array('title' => $val2['zca_title'],'class' => 'c_666 fw_b','onclick'=>"$(this).parent().next('ul').toggle()"))?>
                                            <?php if(!isset($val2['subcat'])) echo CHtml::link($val2['zca_title'],array('/home/product/list', 'id' => $val2['zca_id']), array('title' => $val2['zca_title'],'class' => 'c_666 fw_b'))?>
                                            <span class="c_999 d_n">（<?php echo $val2['pro_count'] ?>）</span></p>
                                            <ul class="sub line_20">
                                              <?php if(isset($val2['subcat'])){  foreach( (array)$val2['subcat'] as $key3=>$val3 ){?>
                                                  <?php if($val3['zca_visible']==1){?>  
                                                    <li><?php echo CHtml::link($val3['zca_title'], array('/home/product/list', 'id' => $val3['zca_id']), array('title' => $val3['zca_title'],'class' => 'c_999'))?><span class="c_999 d_n">（<?php echo $val3['pro_count'] ?>）</span></li>
                                                  <?php }?>
                                              <?php }}?>
                                            </ul>
                                        </li>
                                    <?php }?>
                                <?php }}?>
                                </ul>
                            </div>
                        </li>     
                        <?php }?>               
                    <?php }?>
                </ul>
            </div>
        </div>
        <!--宝贝分类end-->
        <!--热卖单品 start-->
        <div class="pub_a hot_sale c_f mt10 bg_fff">
            <div class="hd bg_x"><span class="c_666 fs_14 fw_b">热卖单品</span></div>
            <div class="bd">
                <ul>
                    <?php 
                    $sql = new CDbCriteria(array(
                                'condition' => 'zp_status = 2 AND zp_state = 2 AND zca_id in ('.$catids.')',
                                'limit' => '5',
                                'order' => 'zp_sale_num DESC'
                            ));
                    $hotpro = Product::model()->findAll($sql);
                    if ($hotpro) {                        
                        foreach ($hotpro as $i) {
                            ?>
                            <li class="c_f">
                                <div class="c_img c_img50 f_l"><?php echo CHtml::link( Tool::thumb( $i->zp_pic,50,50,$i->zp_name ),array('/home/product/detail/', 'id'=>$i->zp_id ),array('target'=>'_blank','title'=>$i->zp_name) ) ?></div>
                                <p class="title title_pro1"><?php echo $i->getTitle() ?></p>
                                <p class="price ff_yh"><strong class="c_orange">&yen;<?php echo $i->zp_price ?></strong></p>
                                <p class="sales c_999">销量：<?php echo $i->zp_sale_num ?>件</p>
                            </li>                            
                            <?php
                        }
                        
                    } else {
                        ?>
                        <p style="text-align:center">没有找到商品!</p>
                    <?php } ?> 
                </ul>
            </div>
        </div>
        <!--热卖单品 end-->
        <!--列表广告 A1 6 start-->
        <?php $adzone = Adzone::model()->getData(6);
        foreach( (array)$adzone['ads'] as $key=>$value){?>
        <div class="adv mt10">
            <?php echo CHtml::link(CHtml::image($value['zds_file_url'],$value['zdz_desc'],array('height'=>$adzone['zdz_height'],'width'=>$adzone['zdz_width']),$value['zds_url'],array('target'=>'_blank')))?>
        </div>
        <?php }?>        
        <!--列表广告 A1 6 end-->
    </div> 
    <div class="col_main w_760 f_r">
        <div class="position bg_x ff_s c_f">
            <span class="f_r d_n">
                <strong class="c_orange"><?php // echo $model->search()->getItemCount(); ?></strong> 件相关商品<?php echo $model->catgory_id?>
            </span>
            <span class="c_999">当前位置：
            		<?php if(!empty($category_top)) echo CHtml::link($category_top->zca_title, array('/home/product/list', 'id' =>$category_top->zca_id), array('title' => $category_top->zca_title))."&gt;"  ?>
            		<?php if(!empty($category_parent)) echo CHtml::link($category_parent->zca_title, array('/home/product/list', 'id' =>$category_parent->zca_id), array('title' => $category_parent->zca_title))."&gt;"  ?>
            		<?php echo CHtml::link($category->zca_title, array('/home/product/list', 'id' =>$category->zca_id), array('title' => $category->zca_title)) ?>
            </span>
        </div>
        <div class="categ_filter bg_fff">
            <?php foreach( (array)$att as $key=>$val){ ?>
            <dl class="c_f">
               <dt class="c_999"><?php echo $val['za_title'] ?>：</dt>
                <dd class="inner" id="Mprice<?php echo $key?>">
                    <?php if(!isset($val['param'])) { ?>
                    <span class="all">
                        <?php if(!isset($val['select'])){
                         	echo CHtml::link("全部",array('/home/product/list','id' => $model->catgory_id), array('title' => '全部','class'=>'cur'));
                        }?>
                    </span>
                    <span class="other">
                        <?php foreach( $val['mark'] as $v) { 
                            echo CHtml::link($v['zpa_val'], array('/home/product/list', 'id' => $model->catgory_id,'att'=>$v['ztc_id']), array('title' => $v['za_title']));
                        }?>                                         
                    </span>
                    <?php } else { ?> 
                    <span class="all">
                        <?php if(!isset($val['select'])||$val['select']==""){
                         	echo CHtml::link('全部', array('/home/product/list', 'id' => $model->catgory_id,'att'=>$val['param']), array('title' => '全部','class'=>'cur'));
                         }else{ 
                            echo CHtml::link('全部', array('/home/product/list', 'id' => $model->catgory_id,'att'=>$val['param']), array('title' => '全部'));
                        }?>
                    </span>
                    <span class="other">
                        <?php 
                        foreach( $val['mark'] as $v)
                        { 
                            if(isset($val['select'])&&($val['select']==$v['ztc_id'])) {
                                echo CHtml::link($v['zpa_val'], array('/home/product/list', 'id' => $model->catgory_id,'att'=>empty($val['param'])?$v['ztc_id']:$val['param'].'-'.$v['ztc_id']), array('title' => $v['za_title'],'class'=>'cur'));
                            }else{
                                echo CHtml::link($v['zpa_val'], array('/home/product/list', 'id' => $model->catgory_id,'att'=>empty($val['param'])?$v['ztc_id']:$val['param'].'-'.$v['ztc_id']), array('title' => $v['za_title']));
                            }
                        }
                        ?>                                         
                    </span>
                    <?php }?>   
                </dd>
                <dd class="more"><a href="javascript:" class="c_06c">更多</a></dd>                               
            </dl>
            <?php }?>   
        </div>
        <div class="pro_list mt10">
            <div class="hd"><span class="bg fs_14 c_white fw_b">所有产品</span></div>   
            <?php   
            	$this->widget('zii.widgets.CListView', array(  
            	    'dataProvider'=>$model->search(20),  
            	    'itemView'=>'_view',    
            	    'emptyText'=>'暂时没有数据',  
            	    'pager'=>array('class'=>'CLinksPager'),
					'cssFile'=>'/css/yii-list-view/styles_h.css',
            		'htmlOptions'=>array('class'=>'list-view pro_list bd'),
            		'itemsTagName'=>'ul',
            		'itemsOptions'=>array('class'=>'list c_f'),
            		'summaryText'=>'第 {start}-{end} 条, 共<strong class="c_red2">{count}</strong> 条   第{page}页/共{pages}页',
            		'pagerTemplate'=>'onlyPager',
            		'buttonCssClass'=>'bg_x btn_page',
            		'batchItemOptions'=>array('class'=>"f_l batchItem"),
            	    'batchItem'=>array(  
            	        //移动到分类  
            	        '<span class="c_666">排序：</span>',  
            	        //添加到分类  
            	        CHtml::link('默认排序',array('list','id' => $model->catgory_id,'att' =>$g_att,'sort'=>''),array('class'=>empty($model->list_order)?"default price":"default")),
            			CHtml::link(($model->list_order==4)?'价格<b class="ico ico_up"></b>':'价格<b class="ico ico_down"></b>',array('list','id' => $model->catgory_id,'att' =>$g_att,'sort'=>($model->list_order==4)?6:4),array('class'=>($model->list_order==4||$model->list_order==6)?"bg_x price":"bg_x")),  
            	   		CHtml::link(($model->list_order==5)?'销量<b class="ico ico_up"></b>':'销量<b class="ico ico_down"></b>',array('list','id' => $model->catgory_id,'att' =>$g_att,'sort'=>($model->list_order==2)?5:2),array('class'=>($model->list_order==2||$model->list_order==5)?"bg_x price":"bg_x")),
            			CHtml::link(($model->list_order==7)?'上架时间<b class="ico ico_up"></b>':'上架时间<b class="ico ico_down"></b>',array('list','id' => $model->catgory_id,'att' =>$g_att,'sort'=>($model->list_order==1)?7:1),array('class'=>($model->list_order==1||$model->list_order==7)?"bg_x price":"bg_x")),
            		 ),  
            	    ));  
            ?>
    </div>
</div>
<div class="hr_30"></div>
<!--热销产品推荐 start-->
<div class="w_960 o_a">
    <div class="pro_recommend bg_fff">
        <div class="hd"><span class="title_hd c_green2">热销产品推荐</span><span class="bg hot"></span></div>
        <div>
            <div class="bd pro_list" id="listBox">
                <ul class="c_f" id="listContent">
                    <?php
                    $sql = new CDbCriteria(array(
                                'condition' => 'zp_status = 2 AND zp_state = 2 AND zca_id in (' .$catids.')',
                                'limit' => '12',
                                'order' => 'zp_sale_num DESC'
                            ));

                    $hotpro = Product::model()->findAll($sql);
                    if ($hotpro) {                        
                        foreach ( (array)$hotpro as $i) {
                            ?>
                            <li class="item">
                                <div class="c_img c_img160"><?php echo CHtml::link( Tool::thumb( $i->zp_pic,160,160,$i->zp_name ),array('/home/product/detail/', 'id'=>$i->zp_id ),array('target'=>'_blank','title'=>$i->zp_name) ) ?></div>
                                <p class="price ff_yh c_f"><strong class="fs_15 c_orange f_r">&yen;<?php echo $i->zp_price ?></strong></p>
                                <p class="title c_666"><?php echo $i->getTitle() ?></p>
                                <p class="buy"><?php echo CHtml::link('点击购买', array('/home/product/detail', 'id' => $i->zp_id), array('title' => '点击购买','class' => 'btn btn_buy'))?></p>
                            </li>                          
                            <?php
                        }                        
                    } else {
                        ?>
                        <p style="text-align:center">没有找到商品!</p>
                    <?php } ?> 
                </ul>
            </div>
        </div>
        <script type="text/javascript">
            new Marquee(["listBox","listContent"],2,0.1,950,328,20,4000,6000,0)
        </script>
    </div>
</div>
<!--热销产品推荐 end-->
<!--正文end-->
<script>
$(function(){    
    <?php foreach( (array)$att as $key=>$val){ ?>
    $("#Mprice<?php echo $key?>").showMore();
    <?php }?>
    $("#proSort").Subsort();
    $("#proSort").Subsort2();
    $(".list_page li").mousedown(function(){
    $(".list_page li ").removeClass("cur");
    $(this).addClass("cur");
    });
});
</script>